package cn.yikaojiuguo.student.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.RelativeLayout;

import cn.yikaojiuguo.student.R;


public class RecordStateView extends RelativeLayout {

	public static final int PRE_RECORD = 0;
	public static final int IS_RECORDING = 1;
	public static final int STOP = 2;
	public static final int IS_PLAYING = 3;
	private static final int CONTINUE_RECORD = 4;
	private int state = PRE_RECORD;
	private FrameLayout fl_recorde;
	private FrameLayout fl_play;
	private FrameLayout fl_ok;
	public ImageButton ib_start_record;
	public ImageButton ib_pause_record;
	public ImageButton ib_play;
	public ImageButton ib_play_pause;
	private ImageButton ib_play_pause_gray;
	public ImageButton ib_ok;
	private ImageButton ib_ok_gray;

	public RecordStateView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		initView();
	}

	public RecordStateView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView();
	}

	public RecordStateView(Context context) {
		super(context);
		initView();
	}

	public int getState() {
		return state;
	}

	public void setState(int state) {
		this.state = state;
		switch (state) {
		case PRE_RECORD:
			fl_play.setVisibility(View.GONE);
			fl_recorde.setVisibility(View.VISIBLE);
			ib_start_record.setVisibility(View.VISIBLE);
			ib_start_record.setEnabled(true);
			ib_pause_record.setVisibility(View.GONE);
			fl_ok.setVisibility(View.GONE);
			break;
		case IS_RECORDING:
			fl_play.setVisibility(View.GONE);
			fl_recorde.setVisibility(View.VISIBLE);
			ib_start_record.setVisibility(View.GONE);
			ib_pause_record.setVisibility(View.VISIBLE);
			fl_ok.setVisibility(View.GONE);
			break;
		case STOP:
			fl_play.setVisibility(View.VISIBLE);
			fl_ok.setVisibility(View.VISIBLE);
			fl_recorde.setVisibility(View.VISIBLE);
			ib_play.setVisibility(View.VISIBLE);
			ib_play_pause.setVisibility(View.GONE);
			ib_play_pause_gray.setVisibility(View.GONE);
			ib_start_record.setVisibility(View.VISIBLE);
			ib_start_record.setEnabled(true);
			ib_pause_record.setVisibility(View.GONE);
			ib_ok.setVisibility(View.VISIBLE);
			ib_ok_gray.setVisibility(View.GONE);
			break;
		case IS_PLAYING:
			fl_play.setVisibility(View.VISIBLE);
			fl_ok.setVisibility(View.VISIBLE);
			fl_recorde.setVisibility(View.VISIBLE);
			ib_play.setVisibility(View.GONE);
			ib_play_pause.setVisibility(View.VISIBLE);
			ib_play_pause_gray.setVisibility(View.GONE);
			ib_ok.setVisibility(View.GONE);
			ib_ok_gray.setVisibility(View.VISIBLE);
			ib_start_record.setVisibility(View.VISIBLE);
			ib_start_record.setEnabled(false);
			ib_pause_record.setVisibility(View.GONE);
			break;
		case CONTINUE_RECORD:
			fl_play.setVisibility(View.VISIBLE);
			fl_ok.setVisibility(View.VISIBLE);
			fl_recorde.setVisibility(View.VISIBLE);
			ib_play.setVisibility(View.GONE);
			ib_play_pause.setVisibility(View.GONE);
			ib_play_pause_gray.setVisibility(View.VISIBLE);
			ib_ok.setVisibility(View.GONE);
			ib_ok_gray.setVisibility(View.VISIBLE);
			ib_start_record.setVisibility(View.GONE);
			ib_pause_record.setVisibility(View.VISIBLE);
			break;
		}
	}

	private void initView() {
		View.inflate(getContext(), R.layout.view_record_state, this);
		fl_recorde = (FrameLayout) findViewById(R.id.fl_recorde);
		fl_play = (FrameLayout) findViewById(R.id.fl_play);
		fl_ok = (FrameLayout) findViewById(R.id.fl_ok);
		ib_start_record = (ImageButton) findViewById(R.id.iv_start_record);
		ib_pause_record = (ImageButton) findViewById(R.id.iv_pause_record);
		ib_play = (ImageButton) findViewById(R.id.iv_play);
		ib_play_pause = (ImageButton) findViewById(R.id.iv_play_pause);
		ib_play_pause_gray = (ImageButton) findViewById(R.id.iv_play_pause_gray);
		ib_ok = (ImageButton) findViewById(R.id.iv_ok);
		ib_ok_gray = (ImageButton) findViewById(R.id.iv_ok_gray);
		setState(PRE_RECORD);
	}

}
